﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace BTCairo
{
    public class BasicRect : BasicShape
    {
        int x, y, width, height;

        public BasicRect(CommonGraphics _comGra, int _x, int _y, int _width, int _height)
        {
            CommonGraphics = _comGra;
            InfoGraphic = _comGra.MyInfoGraphic;
            x = _x;
            y = _y;
            width = _width;
            height = _height;
        }
        public BasicRect(CommonGraphics _comGra)
        {
            CommonGraphics = _comGra;
            InfoGraphic = _comGra.MyInfoGraphic;
            x = InfoGraphic.x;
            y = InfoGraphic.y;
            width = InfoGraphic.widthShape;
            height = InfoGraphic.heightShape;
        }

        public override void Draw()
        {
            CommonGraphics.DrawRect(x, y, width, height);
        }

        public override string ToString()
        {
  //          <rect width="300" height="100"
  //style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/>

            string lineRGB = "rgb(" + InfoGraphic.lineRed + "," + InfoGraphic.lineGreen + "," + InfoGraphic.lineBlue + ")";
            string fillRGB = "rgb(" + InfoGraphic.fillRed + "," + InfoGraphic.fillGreen + "," + InfoGraphic.fillBlue + ")";
            string strSVG = "<rect x=\"" + x + "\" y = \"" + y + "\" width=\"" + width + "\" height=\"" + height + "\" style=\"stroke:" + lineRGB + ";stroke-width:" + InfoGraphic.width;
            if (InfoGraphic.fill)
            {
                strSVG = strSVG + ";fill:" + fillRGB;
            }
            strSVG = strSVG + "\" />" + "\n";
            return strSVG;
        }

        public override void ParseXmlElement(System.Xml.XmlDocument doc, System.Xml.XmlElement root)
        {
            XmlElement node = doc.CreateElement("rect");
            node.SetAttribute("x", x.ToString());
            node.SetAttribute("y", y.ToString());
            node.SetAttribute("width", width.ToString());
            node.SetAttribute("height", height.ToString());
            string lineRGB = "rgb(" + InfoGraphic.lineRed + "," + InfoGraphic.lineGreen + "," + InfoGraphic.lineBlue + ")";
            string fillRGB = "rgba(" + InfoGraphic.fillRed + "," + InfoGraphic.fillGreen + "," + InfoGraphic.fillBlue + ", 255)";
            string style = "stroke:" + lineRGB + ";stroke-width:" + InfoGraphic.width;
            node.SetAttribute("style", style);
            if (InfoGraphic.fill)
            {
                node.SetAttribute("fill", fillRGB);
            }
            else
            {
                fillRGB = "rgba(" + InfoGraphic.fillRed + "," + InfoGraphic.fillGreen + "," + InfoGraphic.fillBlue + ", 0)";
                node.SetAttribute("fill", fillRGB);
            }
            root.AppendChild(node);
        }
    }
}
